/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import Control.SemanticQualificationController;
import Model.FormalConcept;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;

/**
 *
 * @author dark
 */
public class NewFC2 extends javax.swing.JFrame {

    /**
     * Creates new form NewFC2
     */
    
    private static PrincipalWindowGUI pwg;
    
    public NewFC2() {
        initComponents();
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
    
    public NewFC2(PrincipalWindowGUI gui) {
        initComponents();
        pwg = gui;
        pwg.setEnabled(true);
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelFC3 = new javax.swing.JPanel();
        fcCon = new javax.swing.JLabel();
        cfCm = new javax.swing.JButton();
        cfCl = new javax.swing.JButton();
        fcConSel = new javax.swing.JButton();
        cfConceptText = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        fcTitle = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanelFC3.setBackground(new java.awt.Color(196, 200, 202));
        jPanelFC3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanelFC3MouseClicked(evt);
            }
        });

        fcCon.setText("Select the concept in the ontology, then click on select ");

        cfCm.setText("Confirm ");
        cfCm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cfCmActionPerformed(evt);
            }
        });

        cfCl.setText("Cancel ");
        cfCl.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cfClActionPerformed(evt);
            }
        });

        fcConSel.setText("Select");
        fcConSel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fcConSelActionPerformed(evt);
            }
        });

        cfConceptText.setText("??");

        jLabel1.setText("Concept selected : ");

        javax.swing.GroupLayout jPanelFC3Layout = new javax.swing.GroupLayout(jPanelFC3);
        jPanelFC3.setLayout(jPanelFC3Layout);
        jPanelFC3Layout.setHorizontalGroup(
            jPanelFC3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelFC3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanelFC3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelFC3Layout.createSequentialGroup()
                        .addComponent(cfCm)
                        .addGap(75, 75, 75)
                        .addComponent(cfCl))
                    .addGroup(jPanelFC3Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cfConceptText, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanelFC3Layout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addComponent(fcCon)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(fcConSel)
                .addContainerGap(86, Short.MAX_VALUE))
        );
        jPanelFC3Layout.setVerticalGroup(
            jPanelFC3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFC3Layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(jPanelFC3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fcCon)
                    .addComponent(fcConSel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelFC3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cfConceptText)
                    .addComponent(jLabel1))
                .addGap(29, 29, 29)
                .addGroup(jPanelFC3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cfCm)
                    .addComponent(cfCl))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        fcTitle.setText("New Formal Concept");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelFC3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(fcTitle)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(fcTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelFC3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
 
    private static void addAButton(String text, Container container, FormalConcept myFC) {
        MyMenuButton button = new MyMenuButton(text, myFC);
        button.setAlignmentX(Component.CENTER_ALIGNMENT);
        button.setPWG(pwg);
        container.add(button);
    }
    
    public void displayFC(){
        // create the jpanel
        JPanel jp = new JPanel();
        jp.setLayout(new BoxLayout(jp, BoxLayout.Y_AXIS));
        // add buttons
        for (int i = 0; i<pwg.getSQC().FcOntCpt().size(); i++){
            System.out.println(pwg.getSQC().FcOntCpt().get(i));
            addAButton(pwg.getSQC().FcOntCpt().get(i), jp, pwg.getSQC().getFCS().get(i));
        }
        // display ScrollPane
        pwg.getJScrollPane4().getViewport().add(jp, null);
        pwg.doLayout();
        pwg.pack();
    }
    
    private void cfCmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cfCmActionPerformed
        // update the semantic qualification
        pwg.getSQC().updateFormalConceptControl(pwg.getOntologyName(), cfConceptText.getText());
        pwg.getSQC().addFormalConceptControl(pwg.getSQC().getFC());
        pwg.getSQC().setFC(); 
        this.displayFC();
        this.setEnabled(false);
        this.setVisible(false);
        pwg.setEnabled(true); 
    }//GEN-LAST:event_cfCmActionPerformed

    private void cfClActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cfClActionPerformed
        // TODO add your handling code here:
        this.setEnabled(false);
        this.setVisible(false);
        pwg.setEnabled(true);
    }//GEN-LAST:event_cfClActionPerformed

    private void fcConSelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fcConSelActionPerformed
        // TODO add your handling code here:
        cfConceptText.setText(pwg.getTextSelected());
    }//GEN-LAST:event_fcConSelActionPerformed

    private void jPanelFC3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanelFC3MouseClicked
        // TODO add your handling code here:
        this.setEnabled(true);
        System.out.println("mouse clicked");
    }//GEN-LAST:event_jPanelFC3MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(NewFC2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NewFC2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NewFC2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NewFC2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewFC2().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cfCl;
    private javax.swing.JButton cfCm;
    private javax.swing.JLabel cfConceptText;
    private javax.swing.JLabel fcCon;
    private javax.swing.JButton fcConSel;
    private javax.swing.JLabel fcTitle;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanelFC3;
    // End of variables declaration//GEN-END:variables
}
